package com.byxy.mysystem.controller.system;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.byxy.mysystem.model.system.SysPermission;
import com.byxy.mysystem.service.system.ISysPermissionService;
import com.byxy.mysystem.util.JsonResult;
import com.byxy.mysystem.util.ResultTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author omd
 * @since 2022-09-23
 */
@RestController
@RequestMapping("/sysPermission")
public class SysPermissionController {

    @Autowired
    private ISysPermissionService sysPermissionService;

    @PostMapping("/findByPage")
    public JsonResult<IPage<SysPermission>> findByPage(@RequestBody Map<String,Object> params){
        long current = params.get("current") != null?Integer.valueOf(params.get("current").toString()):1;
        long size = params.get("size") != null?Integer.valueOf(params.get("size").toString()):10;
        IPage page = new Page(current,size);
        QueryWrapper<SysPermission> wrapper = new QueryWrapper<>();
        IPage<SysPermission> result = sysPermissionService.page(page,wrapper);
        return ResultTool.success(result);
    }

    @PostMapping("/find")
    public JsonResult<SysPermission> find(Integer id){
        SysPermission sysPermission = sysPermissionService.getById(id);
        return ResultTool.success(sysPermission);
    }

    @PostMapping("/update")
    public JsonResult update(@RequestBody SysPermission sysPermission){
        boolean flag = sysPermissionService.updateById(sysPermission);
        return ResultTool.success(flag);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody SysPermission sysPermission){
        boolean flag = sysPermissionService.save(sysPermission);
        return ResultTool.success(flag);
    }

    @PostMapping("/delete")
    public JsonResult save(List<Integer> ids){
        boolean flag = sysPermissionService.removeByIds(ids);
        return ResultTool.success(flag);
    }
}
